/**
 * Created by liujinghao on 12/11 0011.
 *
 */


var mapRoot = {}; // 地图的根对象
var tileLayer = new BMap.TileLayer();
tileLayer.getTilesUrl = function (tileCoord, zoom) {
    var x = tileCoord.x;
    var y = tileCoord.y;
    return 'image/tile-' + x + '_' + y + '.png';
}
// 绘制手绘地图
var Qmap = new BMap.MapType('Qmap', tileLayer, {minZoom: 14, maxZoom: 18});
var handMap = new BMap.Map('baidumap', {mapType: Qmap});
//handMap.addControl(new BMap.NavigationControl());
handMap.centerAndZoom(new BMap.Point(113.573341369629, 35.6048202514648), 14);
 handMap.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
handMap.disableInertialDragging()

// 绘制卫星地图
// var sateMAP = new BMap.Map("satellite", {mapType: BMAP_SATELLITE_MAP, minZoom: 18, maxZoom: 19, enableMapClick: false});    // 创建Map实例
// sateMAP.centerAndZoom(new BMap.Point(113.933413,35.30537), 14);  // 初始化地图,设置中心点坐标和地图级别
//  sateMAP.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放


var points = [
    {"lng": 113.574437, "lat": 35.60462, "count": 99},
    {"lng": 113.568903, "lat": 35.604268, "count": 99},
    {"lng": 113.566244, "lat": 35.603212, "count": 99},
    {"lng": 113.562292, "lat": 35.601451, "count": 99},
    {"lng": 113.557692, "lat": 35.600218, "count": 99},
    {"lng": 113.555105, "lat": 35.596579, "count": 99},
    {"lng": 113.543535, "lat": 35.592763, "count": 99},
    {"lng": 113.574131, "lat": 35.605251, "count": 45},
    {"lng": 113.570395, "lat": 35.604576, "count": 66},
    {"lng": 113.568203, "lat": 35.604429, "count": 66},
    {"lng": 113.567125, "lat": 35.603813, "count": 68},
    {"lng": 113.561016, "lat": 35.600878, "count": 56},
    {"lng": 113.559256, "lat": 35.600321, "count": 54},
    {"lng": 113.560262, "lat": 35.600732, "count": 55},
    {"lng": 113.538469, "lat": 35.592264, "count": 99},
    {"lng": 113.538846, "lat": 35.592132, "count": 55},
    {"lng": 113.538433, "lat": 35.591633, "count": 23},
    {"lng": 113.539331, "lat": 35.592760, "count": 66},
    {"lng": 113.543535, "lat": 35.592763, "count": 85},
    {"lng": 113.543535, "lat": 35.592763, "count": 65},
    {"lng": 113.543535, "lat": 35.592763, "count": 78}
];
// 热力图图层
heatmapOverlay = new BMapLib.HeatmapOverlay({"radius": 20});
// heatmapOverlay2 = new BMapLib.HeatmapOverlay({"radius": 20});

handMap.addOverlay(heatmapOverlay); // 手绘地图
// sateMAP.addOverlay(heatmapOverlay2); // 卫星图

heatmapOverlay.setDataSet({data: points, max: 100});
// heatmapOverlay2.setDataSet({data: points, max: 100});
handMap.addEventListener("zoomend", function(e){
    // 获取当前级别
    var ZoomNum = handMap.getZoom();
    if (ZoomNum>14) {
        removeMarkerAll.call(mapRoot.landMarkObj);
        mapRoot.landAdd();
    }else{
        removeMarkerAll.call(mapRoot.landMarkObj);
        mapRoot.landAddData();
    }
    
});
//是否显示热力图
heatmapOverlay.show();
function openHeatmap() {
    heatmapOverlay.show();
}
function closeHeatmap() {
    heatmapOverlay.hide();
}

//GPS坐标校准工具函数
function transA(coor) {
    var nc = coor - 0.000001;
    return nc
}
function transB(coor) {
    var nc = coor + 0.000001;
    return nc
}
function newBp(c1, c2) {
    return new BMap.Point(transA(c1), transB(c2))
}
// 测试坐标准确性
function removeMarkerAll() {
    for(x in this){
        if (!this[x].remove) return;
       this[x].remove();
    }
}

/*常态化显示的基础地标*/
var markCoor = {}
markCoor.landMarkData = [
    {id: 'jichu0', name: '八里沟欢迎词', coor: '113.6294140000,35.5509870000',point_type: "1"},
    {id: 'jichu1', name: '绝壁天梯', coor: '113.54116179953,35.58937715608',point_type: "1"},
    {id: 'jichu2', name: '蘑菇石', coor: '113.52980721789,35.587704069894',point_type: "1"},
    {id: 'jichu3', name: '黑龙潭', coor: '113.52698653858,35.586500600124',point_type: "1"},
    {id: 'jichu4', name: '马武居', coor: '113.56922486366,35.604051838693',point_type: "1"},
    {id: 'jichu5', name: '红石河', coor: '113.5374890000,35.5910510000',point_type: "1"},
    {id: 'jichu6', name: '天河瀑布', coor: '113.5394650000,35.5912790000',point_type: "1"},
    {id: 'jichu7', name: '仙人迎客峰', coor: '113.5707620000,35.6047080000',point_type: "1"},
    {id: 'jichu8', name: '一线天', coor: '113.5456270000,35.5959530000',point_type: "1"},
    {id: 'jichu9', name: '玉皇宫', coor: '113.5553730000,35.6026820000',point_type: "1"},
    {id: 'jichu10', name: '丹凤台', coor: '113.59762928389,35.608380351512',point_type: "1"},
    {id: 'jichu11', name: '归真台', coor: '113.60916352664,35.60588598314',point_type: "1"},
    {id: 'jichu12', name: '清峰关', coor: '113.61083749165293,35.61584854428335',point_type: "1"},
    {id: 'jichu13', name: '老君庵', coor: '113.60498,35.610127',point_type: "1"},
    {id: 'jichu14', name: '戏龙台', coor: '113.59626385951,35.611329474063',point_type: "1"},
    {id: 'jichu15', name: '回龙挂壁', coor: '113.62208406878308,35.60563719338466',point_type: "1"},
    {id: 'jichu16', name: '老爷顶', coor: '113.60165369257,35.613808999679',point_type: "1"},
    {id: 'jichu17', name: '如画台', coor: '113.59371267187,35.615261466831',point_type: "1"},
    {id: 'jichu18', name: '闻琴台', coor: '113.59935403047,35.618092967699',point_type: "1"},
    {id: 'jichu19', name: '天梯', coor: '113.561564,35.650564',point_type: "1"},
    {id: 'jichu20', name: '西莲寺', coor: '113.560918,35.651855',point_type: "1"},
    {id: 'jichu21', name: '九莲潭', coor: '113.56013401191,35.649174039876',point_type: "1"}
]
// 创建地标maker
mapRoot.landMarkObj = {};// 所有地标
function landMarker(point, text,wrap) {
    this._point = point;
    this._text = text;
    this._wrap = wrap;
}
landMarker.prototype = new BMap.Overlay();
landMarker.prototype.initialize = function (map) {
    this._map = map;
    var div = this._div = document.createElement("div");
    div.classList.add('land')
    div.style.position = "absolute";
    div.innerHTML = this._text
    this._wrap.getPanes().labelPane.appendChild(div);
    return div;
}
landMarker.prototype.draw = function () {
    var map = this._map;
    var pixel = map.pointToOverlayPixel(this._point);
    this._div.style.left = pixel.x + "px";
    this._div.style.top = pixel.y + "px";
}

mapRoot.landAddData = function () {
    markCoor.landMarkData.forEach(function (val, index) {
        mapRoot.landMarkObj[val.id] = new landMarker(new BMap.Point(val.coor.split(',')[0], val.coor.split(',')[1]), val.name, handMap);
        handMap.addOverlay(mapRoot.landMarkObj[val.id]);
    })
}
mapRoot.landAddData();
// 批量添加基础 地标
mapRoot.landAdd = function () {
    markCoor.landMark.forEach(function (val, index) {
        mapRoot.landMarkObj[val.id] = new landMarker(new BMap.Point(val.coor.split(',')[0], val.coor.split(',')[1]), val.name, handMap);
        handMap.addOverlay(mapRoot.landMarkObj[val.id]);
    })
}

// 获取基础坐标数据
// loadData({
//     type: 'get',
//     url: '/bigdata/manage/map/get-point',
//     interval: 0,
//     callback: function (res) {
//         console.log('基础点位数据', res)
//         markCoor.landMark=[];
//        res.result.forEach(function (val,index) {
//              var obj={};
//              obj.id='jichu'+index;
//              obj.name=val.name;
//              obj.coor=val.coord;
//            markCoor.landMark.push(obj)
//        })
//        console.log(markCoor.landMark)
//         // mapRoot.landAdd();// 添加基础地标
//     }
// })
let resData={
    code: 0,
    msg: "",
   result:[ {point_type: "2", type: "jddw", name: "后静宫", coord: "113.57608596611,35.648342536509", is_show: "1"}
,{point_type: "2", type: "jddw", name: "九莲潭", coord: "113.56013401191,35.649174039876", is_show: "1"}
,{point_type: "2", type: "jddw", name: "天壶瀑布", coord: "113.560397,35.650359", is_show: "1"}
,{point_type: "2", type: "jddw", name: "玄武庙", coord: "113.60127640426,35.616009697099", is_show: "1"}
,{point_type: "2", type: "jddw", name: "求官台", coord: "113.60740284784,35.612517895425", is_show: "1"}
,{point_type: "2", type: "jddw", name: "将军峰", coord: "113.60731301729,35.61134414604", is_show: "1"}
,{point_type: "2", type: "jddw", name: "蜡烛峰", coord: "113.60894793331,35.608879215771", is_show: "1"}
,{point_type: "2", type: "jddw", name: "乌鸦岭", coord: "113.60621708456,35.605533830697", is_show: "1"}
,{point_type: "2", type: "jddw", name: "归真台", coord: "113.60916352664,35.60588598314", is_show: "1"}
,{point_type: "2", type: "jddw", name: "丹凤台", coord: "113.59762928389,35.608380351512", is_show: "1"}
, {point_type: "2", type: "jddw", name: "闻琴台", coord: "113.59935403047,35.618092967699", is_show: "1"}
, {point_type: "2", type: "jddw", name: "听禅台", coord: "113.606288949,35.616244434552", is_show: "1"}
, {point_type: "2", type: "jddw", name: "试胆台", coord: "113.60366589692,35.616347131969", is_show: "1"}
, {point_type: "2", type: "jddw", name: "如画台", coord: "113.59371267187,35.615261466831", is_show: "1"}
, {point_type: "2", type: "jddw", name: "戏龙台", coord: "113.59626385951,35.611329474063", is_show: "1"}
, {point_type: "2", type: "jddw", name: "老爷顶", coord: "113.60171070767,35.613779786187", is_show: "1"}
, {point_type: "2", type: "jddw", name: "清峰关", coord: "113.61085545776,35.615789859692", is_show: "1"}
, {point_type: "2", type: "jddw", name: "老君庵", coord: "113.60498,35.610127", is_show: "1"}
, {point_type: "2", type: "jddw", name: "救帝桑", coord: "113.5384600000,35.5915940000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "猕猴保护区", coord: "113.5552120000,35.5962900000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "一线天", coord: "113.5456270000,35.5959530000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "桃花禅院", coord: "113.57096757635,35.604007818705", is_show: "1"}
, {point_type: "2", type: "jddw", name: "马武居", coord: "113.56922486366,35.604051838693", is_show: "1"}
, {point_type: "2", type: "jddw", name: "百年老屋", coord: "113.54080247733,35.59310478265", is_show: "1"}
, {point_type: "2", type: "jddw", name: "珍珠瀑", coord: "113.52729196246,35.587366513142", is_show: "1"}
, {point_type: "2", type: "jddw", name: "黑龙潭", coord: "113.52698653858,35.586500600124", is_show: "1"}
, {point_type: "2", type: "jddw", name: "蘑菇石", coord: "113.52980721789,35.587704069894", is_show: "1"}
, {point_type: "2", type: "jddw", name: "百年好合树", coord: "113.53873637465,35.590492527272", is_show: "1"}
, {point_type: "2", type: "jddw", name: "点将台", coord: "113.5439285805,35.589054282545", is_show: "1"}
, {point_type: "2", type: "jddw", name: "绝壁天梯", coord: "113.54116179953,35.58937715608", is_show: "1"}
, {point_type: "2", type: "jddw", name: "羊洲地", coord: "113.5492106169,35.593809196343", is_show: "1"}
, {point_type: "2", type: "jddw", name: "西莲寺", coord: "113.560918,35.651855", is_show: "1"}
, {point_type: "2", type: "jddw", name: "天梯", coord: "113.561564,35.650564", is_show: "1"}
, {point_type: "2", type: "jddw", name: "情侣石", coord: "113.5387280000,35.5875590000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "回龙挂壁", coord: "113.62208406878,35.605637193385", is_show: "1"}
, {point_type: "2", type: "jddw", name: "老子布道", coord: "113.5685063212,35.605279837", is_show: "1"}
, {point_type: "2", type: "jddw", name: "静心潭", coord: "113.5666570000,35.6030960000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "玉皇宫", coord: "113.5553730000,35.6026820000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "仙人迎客峰", coord: "113.56576742136,35.606145861398", is_show: "1"}
, {point_type: "2", type: "jddw", name: "天河瀑布", coord: "113.5394650000,35.5912790000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "桃花湾瀑布桃花潭", coord: "113.57434113556,35.604443227215", is_show: "1"}
, {point_type: "2", type: "jddw", name: "桃花湾", coord: "113.5755753055,35.605180687325", is_show: "1"}
, {point_type: "2", type: "jddw", name: "红石河", coord: "113.5374890000,35.5910510000", is_show: "1"}
, {point_type: "2", type: "jddw", name: "抱犊桥将军潭", coord: "113.57067740668,35.604434781169", is_show: "1"}
, {point_type: "2", type: "jddw", name: "八里沟欢迎词", coord: "113.6294140000,35.5509870000", is_show: "1"}]
}
function getALLData(res){
    markCoor.landMark=[];
    res.result.forEach(function (val,index) {
          var obj={};
          obj.id='jichu'+index;
          obj.name=val.name;
          obj.coor=val.coord;
        markCoor.landMark.push(obj)
    })
    console.log(markCoor.landMark)
}
getALLData(resData)
// 这是控制下面时间轴点击效果的
Date.prototype.Format = function (fmt) { //author: meizz
    console.log(fmt)
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
// (new Date()).Format("yyyy-MM-dd hh:mm:ss") ==> 2006-07-02 08:09:04.423

// 底部时间轴对象
var timeline = function () {
    // 绑定点击事件
    this.bindClick();
    this.init('2019-09-18', 30,48);
    this.hotdata = [];
}
timeline.prototype = {
    init: function (date, rate, leng) {
        // date:日期，  rate: 时间粒度，5分钟 10 分钟
        this.date = date;
        this.rate = rate;
        this.scaleWidth = 920; // 刻度盘总宽度
        this.minutesNum = 24 * 60;
        // this.scaleLength = this.minutesNum / this.rate; // 总共划分几个刻度
        this.scaleLength = leng; // 总共划分几个刻度
        this.spotWidth = this.scaleWidth/24 / (60 / rate);
        this.addNumTimes = 1000 * 60 * this.rate; // 每次步进的毫秒数
        this.originalStamp = new Date(date).getTime(); // 零点时候的时间戳  ,  因日期格式原因需要减去8小时
        this.originalStamp = this.originalStamp - 8 * 3600 * 1000
        this.timeList = [];
        this.timelist = this.dateSplit(date, rate);
        this.autoplay = null,
        this.playIndex = 0;
        // 渲染底部时间轴
        this.render(this.date, this.rate);
        $(".tooltip-main").hide();
    },
    dateSplit: function () {
        for (var i = 0; i < this.scaleLength; i++) {
            var tmp = this.originalStamp + this.addNumTimes * i;
            var time = new Date(tmp).Format("yyyy-MM-dd hh:mm:ss");
            this.timeList.push(time)
        }
        return {
            time: this.timeList,
            spotNum: this.scaleLength
        }
    },
    render: function (date, rate) {
        var that = this;
        console.log(this);
        var HtmlFragmeng = document.createDocumentFragment();
        this.timelist.time.forEach(function (val, index) {
            var $spot = $("<div class='spot'></div>");
            var leftPx = that.spotWidth * index;  
            $spot.css('left', leftPx);
            $spot.css('width', that.spotWidth);
            $spot.attr('date', val);
            $spot.attr('index', index);
            $spot.attr('title', val);
            HtmlFragmeng.appendChild($spot[0])
        })
        $("#spotWrap .spot").remove();
        $("#spotWrap").append(HtmlFragmeng)
    },
    bindClick: function () {
        var that = this;
        $("#spotWrap").on('click', '.spot', function (event) {
            if (event.clientX) {  // 人点和机器点
                botTimeline.pause();
                $(".playBtn").show();
                $(".pauseBtn").hide();
                autoRefresh.pause();
            }
            $(".tooltip-main").show();
            if (autoRefresh.status) {
                $(".tooltip-main").hide();
            }
            that.playIndex = parseInt($(this).attr('index'));
            that.spotChange(that.playIndex);// 应用当前点位的热力图数据
            var time = $(this).attr('date').split(' ')[1];
            var leftPx = $(this).css('left');
            $("#spotWrap .tooltip-inner").text(time);
            $("#spotWrap .tooltip-main").css('left', leftPx);
            var hour = $(this).attr('date').split(':')[0].split(' ')[1];
            var minu = $(this).attr('date').split(':')[1].split(':')[0];
            $("#spotWrap .star").css('left', leftPx);
            if (parseInt(minu) == 0) {
                $("#timeline .lis li").removeClass('on');
                //  $("#timeline .lis li").eq(parseInt(hour)).addClass('on')
            } else {
                $("#timeline .lis li").removeClass('on');
            }
        });
        $(".playBtn").on("click", function () {
            botTimeline.play()
            $(".playBtn").hide();
            $(".pauseBtn").show();
            autoRefresh.pause();
        })
        $(".pauseBtn").on("click", function () {
            botTimeline.pause()
            $(".playBtn").show();
            $(".pauseBtn").hide();
            $(".tooltip-main").hide();
        })
        $("#sumPeoNum").on('click', function () {
            $('.c-content .total').toggleClass('dn')
        })
        $("#ms1").on('click', function () {
            $(this).addClass('current').siblings('li').removeClass('current');
            $("#handMap").css('left', 0);
            $("#satellite").css('left', -2000);
        })
        $("#ms2").on('click', function () {
            $(this).addClass('current').siblings('li').removeClass('current');
            $("#handMap").css('left', -2000);
            $("#satellite").css('left', '10px');
        })
        $("#peoNum").on('click', function () {
            $(".peoNum").toggleClass('dn')
        })
        $("#top10Btn").on('click', function () {
            mapRoot.top10toggle();
        })
    },
    spotChange: function (index) {
        //console.log(index)
        //每个时间点对应的人数，热力图，top10点位
        //$(".chartOnlineNum").text(botTimeline.hotdata[index].online);
        // 绘制热力图数据
        heatmapOverlay.setDataSet({data: botTimeline.hotdata[index].hot, max: 100});
        // heatmapOverlay2.setDataSet({data: botTimeline.hotdata[index].hot, max: 100});
    },
    autoClick: function () {
        this.playIndex++;
        if (this.playIndex >= (this.scaleLength + 1)) {
            this.playIndex = 0;
        }
        $("#spotWrap .spot").eq(this.playIndex).click();
    },
    play: function () {
        var that = this;
        this.autoplay = setInterval(function () {
            // console.log(11)
            that.autoClick('robot')
        }, 1000)
    },
    pause: function () {
        if (this.autoplay) {
            //  console.log(000)
            clearInterval(this.autoplay)
        }
    }
}
var botTimeline = new timeline();
// 测试底部时间轴生成
//  botTimeline.init('2017-12-10', 30,48)

$("#hotSearch").on('click', function () {
    var time = $("#date1").val();
    var interval = $("#interval").val();
    console.log(time,interval)
    if (!time) {
        dyw.box.alert('请选择查询时间');
        return false
    }
    getOnlineHot(time, interval);
    clearInterval(autoRefresh.time)
})
// 接口数据
let searchData={
    code: 0,
    msg: "",
    result:{
        date: "2019-11-11",
        timeline:[
{date: "2019-11-11 00:00:00", hot:[
    {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
,{lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
,{lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
,{lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
,{lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
,{lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
,{lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
,{lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
,{lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
,{lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}]}
, {date: "2019-11-11 00:10:00", hot: [
    {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
,{lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
,{lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
,{lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
,{lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
,{lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
,{lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
,{lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
,{lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
,{lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.630049", lat: "35.551881", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
]}
, {date: "2019-11-11 00:20:00", hot: [{lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
,{lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
,{lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
,{lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
,{lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
,{lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
,{lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
,{lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
,{lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
,{lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.630049", lat: "35.551881", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.63203", lat: "35.550236", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}]}
, {date: "2019-11-11 00:30:00", hot:[
    {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
,{lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
,{lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
,{lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
,{lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
,{lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
,{lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
,{lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
,{lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
,{lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.630049", lat: "35.551881", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.629312", lat: "35.54879", people: "1", count: "10"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.63203", lat: "35.550236", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "3", count: "30"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
, {lng: "113.580597", lat: "35.611185", people: "2", count: "20"}
, {lng: "113.581076", lat: "35.604775", people: "1", count: "10"}
, {lng: "113.571952", lat: "35.646237", people: "2", count: "20"}
, {lng: "113.561568", lat: "35.651927", people: "4", count: "40"}
, {lng: "113.615308", lat: "35.59296", people: "3", count: "30"}
, {lng: "113.630381", lat: "35.548724", people: "4", count: "40"}
, {lng: "113.56171", lat: "35.649711", people: "2", count: "20"}
, {lng: "113.628639", lat: "35.550967", people: "1", count: "10"}
, {lng: "113.561568", lat: "35.65181", people: "7", count: "70"}
, {lng: "113.537489", lat: "35.591051", people: "1", count: "10"}
]}
, {date: "2019-11-11 00:40:00", hot: Array(95)}
, {date: "2019-11-11 00:50:00", hot: Array(115)}
, {date: "2019-11-11 01:00:00", hot: Array(135)}
, {date: "2019-11-11 01:10:00", hot: Array(132)}
, {date: "2019-11-11 01:20:00", hot: Array(129)}
, {date: "2019-11-11 01:30:00", hot: Array(126)}
, {date: "2019-11-11 01:40:00", hot: Array(125)}
, {date: "2019-11-11 01:50:00", hot: Array(126)}
, {date: "2019-11-11 02:00:00", hot: Array(126)}
, {date: "2019-11-11 02:10:00", hot: Array(127)}
, {date: "2019-11-11 02:20:00", hot: Array(126)}
, {date: "2019-11-11 02:30:00", hot: Array(126)}
, {date: "2019-11-11 02:40:00", hot: Array(126)}
, {date: "2019-11-11 02:50:00", hot: Array(124)}
, {date: "2019-11-11 03:00:00", hot: Array(120)}
, {date: "2019-11-11 03:10:00", hot: Array(116)}
, {date: "2019-11-11 03:20:00", hot: Array(113)}
, {date: "2019-11-11 03:30:00", hot: Array(111)}
, {date: "2019-11-11 03:40:00", hot: Array(111)}
, {date: "2019-11-11 03:50:00", hot: Array(111)}
, {date: "2019-11-11 04:00:00", hot: Array(109)}
, {date: "2019-11-11 04:10:00", hot: Array(110)}
, {date: "2019-11-11 04:20:00", hot: Array(111)}
, {date: "2019-11-11 04:30:00", hot: Array(113)}
, {date: "2019-11-11 04:40:00", hot: Array(114)}
, {date: "2019-11-11 04:50:00", hot: Array(114)}
, {date: "2019-11-11 05:00:00", hot: Array(115)}
, {date: "2019-11-11 05:10:00", hot: Array(118)}
, {date: "2019-11-11 05:20:00", hot: Array(123)}
, {date: "2019-11-11 05:30:00", hot: Array(131)}
, {date: "2019-11-11 05:40:00", hot: Array(137)}
, {date: "2019-11-11 05:50:00", hot: Array(145)}
, {date: "2019-11-11 06:00:00", hot: Array(156)}
, {date: "2019-11-11 06:10:00", hot: Array(167)}
, {date: "2019-11-11 06:20:00", hot: Array(178)}
, {date: "2019-11-11 06:30:00", hot: Array(188)}
, {date: "2019-11-11 06:40:00", hot: Array(198)}
, {date: "2019-11-11 06:50:00", hot: Array(208)}
, {date: "2019-11-11 07:00:00", hot: Array(219)}
, {date: "2019-11-11 07:10:00", hot: Array(229)}
, {date: "2019-11-11 07:20:00", hot: Array(259)}
, {date: "2019-11-11 07:30:00", hot: Array(297)}
, {date: "2019-11-11 07:40:00", hot: Array(340)}
, {date: "2019-11-11 07:50:00", hot: Array(389)}
, {date: "2019-11-11 08:00:00", hot: Array(435)}
, {date: "2019-11-11 08:10:00", hot: Array(477)}
, {date: "2019-11-11 08:20:00", hot: Array(510)}
, {date: "2019-11-11 08:30:00", hot: Array(524)}
, {date: "2019-11-11 08:40:00", hot: Array(538)}
, {date: "2019-11-11 08:50:00", hot: Array(549)}
, {date: "2019-11-11 09:00:00", hot: Array(559)}
, {date: "2019-11-11 09:10:00", hot: Array(570)}
, {date: "2019-11-11 09:20:00", hot: Array(582)}
, {date: "2019-11-11 09:30:00", hot: Array(589)}
, {date: "2019-11-11 09:40:00", hot: Array(586)}
, {date: "2019-11-11 09:50:00", hot: Array(582)}
, {date: "2019-11-11 10:00:00", hot: Array(582)}
, {date: "2019-11-11 10:10:00", hot: Array(573)}
, {date: "2019-11-11 10:20:00", hot: Array(561)}
, {date: "2019-11-11 10:30:00", hot: Array(558)}
, {date: "2019-11-11 10:40:00", hot: Array(561)}
, {date: "2019-11-11 10:50:00", hot: Array(560)}
, {date: "2019-11-11 11:00:00", hot: Array(562)}
, {date: "2019-11-11 11:10:00", hot: Array(561)}
, {date: "2019-11-11 11:20:00", hot: Array(560)}
, {date: "2019-11-11 11:30:00", hot: Array(555)}
, {date: "2019-11-11 11:40:00", hot: Array(541)}
, {date: "2019-11-11 11:50:00", hot: Array(533)}
, {date: "2019-11-11 12:00:00", hot: Array(521)}
, {date: "2019-11-11 12:10:00", hot: Array(510)}
, {date: "2019-11-11 12:20:00", hot: Array(501)}
, {date: "2019-11-11 12:30:00", hot: Array(502)}
, {date: "2019-11-11 12:40:00", hot: Array(510)}
, {date: "2019-11-11 12:50:00", hot: Array(510)}
, {date: "2019-11-11 13:00:00", hot: Array(517)}
, {date: "2019-11-11 13:10:00", hot: Array(520)}
, {date: "2019-11-11 13:20:00", hot: Array(526)}
, {date: "2019-11-11 13:30:00", hot: Array(531)}
, {date: "2019-11-11 13:40:00", hot: Array(537)}
, {date: "2019-11-11 13:50:00", hot: Array(544)}
, {date: "2019-11-11 14:00:00", hot: Array(559)}
, {date: "2019-11-11 14:10:00", hot: Array(565)}
, {date: "2019-11-11 14:20:00", hot: Array(577)}
, {date: "2019-11-11 14:30:00", hot: Array(584)}
, {date: "2019-11-11 14:40:00", hot: Array(583)}
, {date: "2019-11-11 14:50:00", hot: Array(578)}
, {date: "2019-11-11 15:00:00", hot: Array(570)}
, {date: "2019-11-11 15:10:00", hot: Array(561)}
, {date: "2019-11-11 15:20:00", hot: Array(559)}
, {date: "2019-11-11 15:30:00", hot: Array(554)}
, {date: "2019-11-11 15:40:00", hot: Array(557)}
, {date: "2019-11-11 15:50:00", hot: Array(561)}
, {date: "2019-11-11 16:00:00", hot: Array(563)}
, {date: "2019-11-11 16:10:00", hot: Array(565)}
, {date: "2019-11-11 16:20:00", hot: Array(563)}
        ]
    }
}

function getOnlineHot(time, interval) {
    var opt = {};
    if (time) {
        opt.time = time
    }
    if (interval) {
        opt.interval = interval
    } else {
        opt.interval = 10     // 默认时间粒度  单位：分钟
    }
    // loadData({
    //     type: 'get',
    //     url: '/bigdata/manage/heatmap/heatmap',
    //     data: opt,
    //     interval: 0,
    //     callback: function (res) {
    //         console.log('返回查询数据', res)
    //         if (res.code == 1) {
    //             dyw.box.alert(res.msg);
    //             return false
    //         }
    //         hotSearchChange(res, opt.interval)
    //         $("#date1").val(res.result.date)
    //     }
    // })
    function searchAllData(res){
        console.log(res)
        if (res.code == 1) {
            dyw.box.alert(res.msg);
            return false
        }
        hotSearchChange(res, opt.interval)
        $("#date1").val(res.result.date)
    }
    
    searchAllData(searchData)
}

// 默认页面打开显示今天
getOnlineHot()
function hotSearchChange(res, interval) {
    // 分时段热力图数据
    botTimeline.hotdata = res.result.timeline;
    console.log(botTimeline.hotdata)
    // 渲染底部进度条
    if (!botTimeline.hotdata.length) {
        console.log('接口数据为空')
        return;
    }
    var day = botTimeline.hotdata[0].date.split(' ')[0];
    botTimeline.init(day, interval, botTimeline.hotdata.length); // 根据接口数据粒度绘制底部时间轴
    var localToday = (new Date()).Format("yyyy-MM-dd");
    // 如果是今天，并且为自动刷新模式，则要自动点击最后一个时间点 ，用于更新热力图和top10点位
    if (autoRefresh.status && (day == localToday)) {
        autoRefresh.isToday = true;
        autoRefresh.start(); // 启动自动刷次
        $("#spotWrap .spot:last").click();   // 自动点击最后一个
    } else {
        autoRefresh.isToday = false;
        $("#spotWrap .spot:first").click();   // 点击第一个
        autoRefresh.pause();
        timeline.play()
    }

}

// 顶部的自动刷新功能
var autoRefresh = {
    name: '自动刷新',
    status: false,
    isToday: false,
    time: null,
    click: function () {
        if (!this.isToday) {
            alert('自动刷新功能仅用于查看今天的实时数据')
        }
        if (this.status) {
            this.pause()
        } else {
            console.log('启用自动刷新')
            this.start()
        }
    },
    start: function () {
        this.status = true;
        if (this.time) clearInterval(autoRefresh.time)
        this.time = setInterval(this.refresh, 1000 * 60 * 3)
        $("#refresh").text('暂停刷新');
        if ($(".pauseBtn").is(':visible')) {
            $(".pauseBtn").click();
        }
    },
    pause: function () {
        this.status = false;
        clearInterval(this.time)
        $("#refresh").text('自动刷新');
    },
    refresh: function () {
        getOnlineHot();// 请求今天数据
    }
};
autoRefresh.start();

$("#refresh").on('click', function () {
    autoRefresh.click();
})
